<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="icon" type="image/x-icon" th:href="@{/image/blog.ico}"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加博客</title>
    <link href="https://unpkg.com/@wangeditor/editor@latest/dist/css/style.css" rel="stylesheet">
    <style>
        body {
            margin: 0;
            padding: 0;
        }

        .content {
            height: 100%;
            width: 100%;
            margin: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
        }

        form {
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
        }

        /* 导航栏样式 */
        .navbar {
            overflow: hidden;
            background-color: gray;
        }

        .navbar a {
            float: left;
            display: block;
            color: #f2f2f2;
            text-align: center;
            padding: 14px 16px;
            text-decoration: none;
        }

        .navbar a.right {
            float: right;
        }

        /*富文本编辑器样式*/

        #editor—wrapper {
            width: 80%;
            border: 1px solid #ccc;
            z-index: 100; /* 按需定义 */
        }

        #toolbar-container {
            border-bottom: 1px solid #ccc;
        }

        #editor-container {
            height: 500px;
        }

    </style>
</head>
<body>
<!-- Navigation bar -->
<div class="navbar">
    <a href="#">Blog</a>
    <a href="/admin/add">添加</a>
    <a href="#" class="right" th:text="${session.username}">Your Name</a>
</div>
<div class="content">
    <form action="/admin/doAdd" method="post" th:object="${Blog}">
        <div id="contentDiv1" style="margin-top: 20px; margin-left: 30px">
            <label for="textInput">标题：</label>
            <input type="text" id="textInput" name="title" placeholder="请输入标题"
                   style="padding: 10px; margin-bottom: 10px;">
        </div>

        <input id="blogContent" type="text" name="content" style="display: none"> </input>

        <!--wangEditor富文本编辑器-->
        <div id="editor—wrapper">
            <div id="toolbar-container"><!-- 工具栏 --></div>
            <div id="editor-container"><!-- 编辑器 --></div>
        </div>

        <button id="saveButton" type="submit" style="padding: 10px 20px; margin-top: 20px; margin-bottom: 30px">保存</button>
    </form>
</div>


<script src="https://unpkg.com/@wangeditor/editor@latest/dist/index.js"></script>
<script>
    const {createEditor, createToolbar} = window.wangEditor

    const editorConfig = {
        placeholder: '请输入博客内容',
        onChange(editor) {
            const html = editor.getHtml()
            var divElement = document.getElementById("blogContent");
            divElement.value = html;
            console.log('editor content', html)

            // 也可以同步到 <textarea>
        }
    }

    const editor = createEditor({
        selector: '#editor-container',
        html: '<p><br></p>',
        config: editorConfig,
        mode: 'default', // or 'simple'
    })

    const toolbarConfig = {}

    const toolbar = createToolbar({
        editor,
        selector: '#toolbar-container',
        config: toolbarConfig,
        mode: 'simple', // or 'simple'
    })
</script>
</body>
</html>
